package com.agileboot.domain.system.danger.model;

import com.agileboot.common.exception.ApiException;
import com.agileboot.common.exception.error.ErrorCode;

import com.agileboot.domain.system.danger.db.DangerSourceEntity;
import com.agileboot.domain.system.danger.db.DangerSourceService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class DangerSourceModelFactory {

    private final DangerSourceService dangerSourceService;

    public DangerSourceModel loadById(Long id) {
        DangerSourceEntity entity = dangerSourceService.getById(id);
        if (entity == null) {
            throw new ApiException(ErrorCode.Business.COMMON_OBJECT_NOT_FOUND, id, "危险源");
        }
        return new DangerSourceModel(entity, dangerSourceService);
    }

    public DangerSourceModel create() {
        return new DangerSourceModel(dangerSourceService);
    }
}
